package com.xzy.controller;

import com.xzy.Service.NewCustomerFewStrategy;
import com.xzy.Service.NewCustomerManyStrategy;
import com.xzy.Service.OldCustomerFewStrategy;
import com.xzy.Service.Strategy;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.ApplicationContext;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * 定义环境,传递策略id
 */
@RestController
public class PriceContext {
    @Autowired
    private ApplicationContext applicationContext;
    @RequestMapping("/price")
    public void printlnPrice(String standard,double s){
        Object bean = applicationContext.getBean(standard);
        System.out.println(bean.getClass());
        Strategy st = (Strategy) applicationContext.getBean(standard);
        System.out.println(st.getPrice(s));
    }

}
